import { getModularity } from './getModularity.js';
import getH from './getH';
import localSearch from './localSearch.js';
function evaluateMFEA(
  matrixs,
  edgeDatas,
  obj,
  useLocalSearch,
  useLocalSearchProbability = 0,
  targetFunction,
  bestValues,
  w
) {
  let getTargetValue;
  if (targetFunction === 'G') getTargetValue = getModularity;
  else if (targetFunction === 'H') getTargetValue = getH;
  if (useLocalSearch) {
    if (obj.skillFactor === -1) {
      for (let i = 0; i < matrixs.length; i++) {
        obj.factorialCosts[i] = getTargetValue(matrixs[i], obj.rnvec, edgeDatas[i], w);
      }
    } else {
      obj.factorialCosts.fill(-Infinity);
      if (Math.random() < useLocalSearchProbability) {
        obj.factorialCosts[obj.skillFactor] = localSearch(
          matrixs[obj.skillFactor],
          obj.rnvec,
          edgeDatas[obj.skillFactor],
          targetFunction,
          bestValues[obj.skillFactor].rnvec,
          w
        );
      } else {
        obj.factorialCosts[obj.skillFactor] = getTargetValue(
          matrixs[obj.skillFactor],
          obj.rnvec,
          edgeDatas[obj.skillFactor],
          w
        );
      }
    }
  } else {
    if (obj.skillFactor === -1) {
      for (let i = 0; i < matrixs.length; i++) {
        obj.factorialCosts[i] = getTargetValue(matrixs[i], obj.rnvec, edgeDatas[i]);
      }
    } else {
      obj.factorialCosts.fill(-Infinity);
      obj.factorialCosts[obj.skillFactor] = getTargetValue(
        matrixs[obj.skillFactor],
        obj.rnvec,
        edgeDatas[obj.skillFactor],
        w
      );
    }
  }
}
export default evaluateMFEA;
